import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-02-19
 * Time: 22:19
 */
public class Main {
    //合并两个有序数组
    public static void merge(int[] num1, int m, int[] num2, int n) {
        int[] array = new int[m + n];
        for(int i = 0;i < m;i++){
            array[i] = num1[i];
        }
        for(int j = m;j < m + n;j++){
            array[j] = num2[j - m];
        }
        for(int i = 0;i < m + n - 1;i++){
            int temp = 0;
            for (int j = 0; j < m + n - 1 - i; j++) {
                if (array[j] > array[j + 1]){
                    temp = array[j+1];
                    array[j+1] = array[j];
                    array[j] = temp;
                }
            }
        }
        for(int i = 0;i < m + n;i++){
            num1[i] = array[i];
        }
    }
    //杨辉三角
    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> list = new ArrayList<>();
        List<Integer> row = new ArrayList<>();
        row.add(1);
        list.add(row);
        for (int i = 1; i < numRows; i++) {
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);
            List<Integer> preRow = list.get(i-1);
            for (int j = 1; j < i; j++) {
                int x = preRow.get(j) + preRow.get(j - 1);
                curRow.add(x);
            }
            curRow.add(1);
            list.add(curRow);
        }
        return list;
    }
    //移除元素
    public static int removeElement(int[] num, int val) {
        int count = 0;
        for(int i = 0;i < num.length;i++){
            if(num[i] != val){
                count++;
            }
        }
        int index = 0;
        for(int j = 0;j < num.length;j++){
            if(num[j] != val){
                num[index] = num[j];
                index++;
            }
        }
        return count;
    }
    //删除有序数组的重复项
    public static int removeDuplicates(int[] num) {
        if(num == null || num.length == 0) return 0;
        int p = 0;
        int q = p + 1;
        while(p < q && q < num.length){
            if(num[p] == num[q]){
                q++;
            }else{
                num[p + 1] = num[q];
                p++;
                q++;
            }
        }
        return p + 1;
    }

    public static void main(String[] args) {
        int[] num = new int[]{7,2,3,3,45,2,7};
        removeDuplicates(num);
    }



    public static void main3(String[] args) {
        int[] num = new int[]{7,2,3,3,45,2,7};
        removeElement(num,7);
    }



    public static void main2(String[] args) {
        System.out.println(generate(8));
    }



    public static void main1(String[] args) {
        int[] num1 = new int[]{7,2,3};
        int[] num2 = new int[]{4,5,6};
        merge(num1,3,num2,3);
    }
}